//
//  UIView+CLKit.m
//  Rippton_iphone
//
//  Created by yeyongping on 2018/1/11.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "UIView+CLKit.h"

@implementation UIView (CLKit)
/**
 当前view所在的控制器
 */
- (UIViewController *)cl_currentVc{
    UIResponder *next = [self nextResponder];
    do {
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        next = [next nextResponder];
    } while (next != nil);
    return nil;
}
/**
 设置对应的圆角
 */
- (void)setCl_cornerRadius:(CGFloat)cl_cornerRadius{
    //rect: 需要画的矩形的Frame
    //corners: 哪些部位需要画成圆角
    //cornerRadii: 圆角的Size
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(cl_cornerRadius, cl_cornerRadius)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = self.bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
    //    self.layer.masksToBounds = YES;
    
}
- (CGFloat)cl_cornerRadius{
    @throw [NSException exceptionWithName:@"dont get cl_connerRadious" reason:@"不可以读取分类中定义的属性成员变量" userInfo:nil];
    //    return 0;
}
- (void)setCl_borderColor:(UIColor *)cl_borderColor{
    self.layer.borderColor = cl_borderColor.CGColor;
    
}
- (UIColor *)cl_borderColor{
    @throw [NSException exceptionWithName:@"dont get cl_borderColor" reason:@"不可以读取分类中定义的属性成员变量" userInfo:nil];
}
- (void)setCl_borderWidth:(CGFloat)cl_borderWidth{
    self.layer.borderWidth = cl_borderWidth;
}
- (CGFloat)cl_borderWidth{
    @throw [NSException exceptionWithName:@"dont get cl_borderWidth" reason:@"不可以读取分类中定义的属性成员变量" userInfo:nil];
}
@end
